package com.leetcode.LC;

public class LC541 {
    public String reverseStr(String s, int k) {
        char[] chars = s.toCharArray();
        int i, j;
        char tmp;
        for (int l = 0; l < s.length(); l += 2 * k) {
            i=l;
            j=Math.min(l+k-1,s.length()-1);
            while (i<j){
                tmp=chars[i];
                chars[i]=chars[j];
                chars[j]=tmp;
                i++;
                j--;
            }
        }
        return new String(chars);
    }

    public static void main(String[] args) {
        System.out.println(new LC541().reverseStr("abcdefg", 2));
    }
}
